/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.meuevento.business.event;

import com.meuevento.business.user.User;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Fernando Arena Varella (favarella@inf.ufrgs.br)
 */
@Entity
@Cacheable(false)
@NamedQueries({@NamedQuery(name = "Event.findByName", query = "SELECT e FROM Event e WHERE e.name = :name"),@NamedQuery(name = "Event.findById", query = "SELECT e FROM Event e WHERE e.eventId = :id")})
public class Event implements Serializable {
     public static final String FIND_BY_NAME = "Event.findByName";
    public static final String FIND_BY_ID = "Event.findById";

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long eventId;

    @Column
    private String name;

    @Column
    //TODO: trocar por objeto Location/Place/etc
    private String place;

    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private GregorianCalendar startDate;

    @ManyToMany(cascade=CascadeType.ALL)
    private List<User> users;

    public Event(String name, String place, GregorianCalendar startDate) {
        this.name = name;
        this.place = place;
        this.startDate = startDate;
    }
//    private List<User> users;

    public Event(){
        
    }



    public void addUser(User user){
        if (users == null)
            users = new ArrayList<User>();
        users.add(user);
    }





    public Long getEventId() {
        return eventId;
    }

    public void setEventId(Long id) {
        this.eventId = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public GregorianCalendar getStartDate() {
        return startDate;
    }

    public void setStartDate(GregorianCalendar startDate) {
        this.startDate = startDate;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

//    public User getUser() {
//        return user;
//    }
//
//    public void setUser(User user) {
//        this.user = user;
//    }







    @Override
    public int hashCode() {
        int hash = 0;
        hash += (eventId != null ? eventId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.eventId == null && other.eventId != null) || (this.eventId != null && !this.eventId.equals(other.eventId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.meuevento.business.event.Event[id=" + eventId + "]";
    }

}
